package util;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;

import java.util.HashMap;

public class SMSUtil {

    /**
     * 发送快递取件码短信
     * @param phoneNumber
     * @param code
     * @return
     */
    public static boolean sendExpressCode(String phoneNumber,String code){
        //你的accessKeyId && 你的AccessKeySecret
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "你的accessKeyId", "你的AccessKeySecret");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.ap-southeast-1.aliyuncs.com");//dysmsapi.aliyuncs.com
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        //电话号码
        request.putQueryParameter("PhoneNumbers", phoneNumber);
        //短信签名名称
        request.putQueryParameter("SignName", "短信签名名称");
        //短信模板CODE
        request.putQueryParameter("TemplateCode", "短信模板CODE");
        //短信验证码
        request.putQueryParameter("TemplateParam", "{\"code\":\""+code+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
            String json = response.getData();
            Gson g = new Gson();
            HashMap result = g.fromJson(json, HashMap.class);
            if("OK".equals(result.get("Message"))) {
                return true;
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 发送微信登录验证码短息
     * @param phoneNumber
     * @param code
     * @return
     */
    public static boolean sendWxLoginCode(String phoneNumber,String code){


        return false;
    }



}




